package com.wanhe.shoppingcart.bean;

import com.wanhe.base.util.ObjectUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 套餐的购车车选项类型
 * Created by Administrator on 2016/6/2.
 */
public class SetMealCartItem extends CartItem {

	/**
	 * 套餐子菜品的集合
	 */
	private List<CartItem> arrChildItem;

	public List<CartItem> getArrChildItem() {
		if (arrChildItem == null) {
			arrChildItem = new ArrayList<>();
		}
		return arrChildItem;
	}

	public void setArrChildItem(List<CartItem> arrChildItem) {
		this.arrChildItem = arrChildItem;
	}

	public void addChildItem(CartItem childItem){
		if(arrChildItem == null){
			arrChildItem = new ArrayList<>(5);
		}
		arrChildItem.add(childItem);
	}

	@Override
	public boolean isSellOut(int count) {
		boolean isSellOut = super.isSellOut(count);
		if (isSellOut)
			return isSellOut;
		if (ObjectUtil.checkObjectList(arrChildItem)) {
			for (int i = 0; i < getArrChildItem().size(); i++) {
				CartItem cartItem = getArrChildItem().get(i);
				boolean sallOut = cartItem.isSellOut(count);
				if (sallOut) {
					return sallOut;
				}
			}
		}
		return isSellOut;
	}


	public boolean isFatherSellOut(int count) {
		boolean isSellOut = super.isSellOut(count);
		return isSellOut;
	}

	@Override
	public String getSignID() {
		String newSignId =  getDishGuid() + getAddTime();
		return newSignId;
	}


	@Override
	public double getPrice() {
		double price = super.getPrice();
		if (!ObjectUtil.checkObjectList(arrChildItem))
			return price;
		for (CartItem item : arrChildItem) {
			price += item.getPrice();
		}
		return price;
	}

	@Override
	public double getVIPPrice() {
		double price = super.getVIPPrice();
		if (!ObjectUtil.checkObjectList(arrChildItem))
			return price;
		for (CartItem item : arrChildItem) {
			price += item.getVIPPrice();
		}
		return price;
	}


	@Override
	public double getCalorieCount() {
		double count = 0;
		count += super.getCalorieCount();
		if (ObjectUtil.checkObjectList(arrChildItem)) {
			for (int i = 0; i < arrChildItem.size(); i++) {
				count += arrChildItem.get(i).getCalorieCount();
			}
		}
		return count;
	}


}
